package win.doyto.service.data.report;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.cursor.Cursor;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * ReportMapper
 *
 * @author f0rb on 2017-12-20.
 */
@SuppressWarnings("java:S1214")
@Mapper
public interface ReportMapper {

    String SQL_KEY = "sql";
    String SHOW_ROW_NUMBER = "showRN";

    @Select("<script>${" + SQL_KEY + "}</script>")
    @Options(useCache = false, fetchSize = 100)
    Cursor<LinkedHashMap<String, Object>> getData(Map<String, ?> map);

    @Select("SELECT @rn:=@rn+1 as ${" + SHOW_ROW_NUMBER + "}, t.* FROM (${" + SQL_KEY + "}) t, (Select (@rn :=0) ) r")
    @Options(useCache = false, fetchSize = 100)
    Cursor<LinkedHashMap<String, Object>> getDataWithRowNum(Map<String, ?> map);

    @Select("SELECT t.* FROM (SELECT 0) AS d LEFT JOIN (${" + SQL_KEY + "} limit 0) AS t ON 1 = 1;")
    @Options(useCache = false)
    LinkedHashMap<String, Object> getNullRowForTitle(Map<String, ?> map);
}
